package com.ruoyi.web.controller.comlbs;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ElectricFence;
import com.ruoyi.system.domain.request.alarmrule.BindAlarmRuleParam;
import com.ruoyi.system.service.IAlarmRuleFenceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 告警规则绑定电子围栏的中间Controller
 * 
 * @author wp
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/comlbs/alarmRuleFence")
public class AlarmRuleFenceController extends BaseController {

    @Autowired
    private IAlarmRuleFenceService alarmRuleFenceService;

    @ApiOperation("报警规则绑定围栏列表")
    @ApiOperationSupport(includeParameters = {"name","type","companyId","alarmRuleId"})
    @GetMapping("/list")
    public TableDataInfo list(ElectricFence ElectricFence) {
        startPage();
        List<ElectricFence> list = alarmRuleFenceService.selectList(ElectricFence);
        return getDataTable(list);
    }

    /**
     * 获取告警规则绑定电子围栏的中间详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(alarmRuleFenceService.getById(id));
    }

    @ApiOperation("报警规则绑定围栏")
    @Log(title = "报警规则绑定围栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult bindFence(@Validated @RequestBody BindAlarmRuleParam param) {
        alarmRuleFenceService.bindFence(param);
        return success();
    }
}
